package com.zhangyx.crawler.comm;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {
    private static Properties props;

    static {
        init();
    }

    private static void init() {
        InputStream ins = PropertiesUtil.class.getClassLoader().getResourceAsStream("config.properties");
        try {
            props = new Properties();
            props.load(ins);
            ins.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static String get(String name, String defaultValue) {
        return props.getProperty(name, defaultValue);
    }

    public static String get(String name) {
        return props.getProperty(name);
    }

    public static Integer getInt(String name) {
        return Integer.parseInt(props.getProperty(name));
    }

    public static void main(String[] args){
        System.out.println(get("redis.host"));
    }
}
